<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta http-equiv="Access-Control-Allow-Origin" content="*">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <!-- 引入样式 -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  <!-- 引入组件库 -->

  <title>上传文件测试</title>
  <style>
    .active {
      border: 1px solid red;
    }
  </style>
</head>

<body>
<div id="app">
  <div style="height: 300px;width: 300px">
    <el-upload
            class="upload-demo"
            ref="upload"
            action="http://localhost:8080/admin/uploadfile"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :file-list="fileList"
            :auto-upload="false">
      <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
      <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
      <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
    </el-upload>
  </div>

</div>



<!-- 两种方法载入Vue.js -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
  var app = new Vue({
    el: "#app", //挂载点
    data() {
      return {
        fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}]
      };
    },
    methods: {
      submitUpload() {
        // axios.put("http://localhost:8080/admin/uploadfile",this.$refs.upload);
        // console.log(this.fileList);
        // this.$refs.upload.submit();
        axios.post("http://localhost:8080/admin/uploadfile",{params:{
            "file":this.fileList
          }}).then(
                function(response ){
                  console.log(response);
                },function(err){
                  //接口连接失败返回的信息
                  console.log(err);
                });
      },
      handleRemove(file, fileList) {
        fileList.pop()
        // console.log(file, fileList);
      },
      handlePreview(file) {
        console.log(file);
      }
    }

  })


</script>
<!-- 官网提供的axios在线地址 -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

</body>

</html>